<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
<title></title>
<link href="<s:url value='/common/lib/ligerUI/skins/Aqua/css/ligerui-all.css'/>" rel="stylesheet" type="text/css" />
<link href="<s:url value='/common/lib/ligerUI/skins/ligerui-icons.css'/>" rel="stylesheet" type="text/css" />
<script src="<s:url value='/common/lib/jquery/jquery-1.3.2.min.js'/>" type="text/javascript"></script>
<script src="<s:url value='/common/lib/ligerUI/js/core/base.js'/>" type="text/javascript"></script>
<script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerDialog.js'/>" type="text/javascript"></script>
<script type="text/javascript">
        $(function () {
        	$("#stroragePathBox").hide();
        	$("#delBox").hide();
        	$("#infoBox").hide();
        	$("#dealerCodeText").focus();
        });
        
        function deleteData() {
        	var ts = $("#ts").val();
        	var dc = $("#dealerCodeText").val();
        	var times =  ts.split("-");
        	$.ligerDialog.confirm('确定要删除该经销商' + times[0] + '年' + times[1] + '月' + times[2] + '号的数据?', function (yes) {
        		if(yes) {
        			$("#delBtn").attr("disabled", "disabled");
        			$("#stroragePath").attr("disabled", "disabled");
        			$("#infoBox").show();
        			$.post("<s:url value='/record/deleteData.action'/>",{dealerCode:dc, timeStamp:ts}, function(data) {
        				$("#infoBox").hide();
        				if(data == 0) {
        					$.ligerDialog.alert('该经销商' + times[0] + '年' + times[1] + '月' + times[2] + '号的数据已删除', '提示', 'success');
        					$("#delBtn").attr("disabled", "");
                			$("#stroragePath").attr("disabled", "");
                			$("#stroragePath option[value='" + ts + "']").remove();
        				} else {
        					$.ligerDialog.alert('系统忙,请稍后再试！', '提示', 'error');
        					$("#delBtn").attr("disabled", "");
                			$("#stroragePath").attr("disabled", "");
        				}
        			});
        		}
        	});
        }
        
        function inputDealerCode() {
        	$.post("<s:url value='/record/validDealerCode.action'/>",{dealerCode : $("#dealerCodeText").val()}, function(data) {
    			if(data != 0) {
    				$.ligerDialog.alert('您输入的经销商网代码有误，请重新输入!', '提示', 'error');
    				$("#dealerCodeText").val("");
    				$("#dealerCodeText").focus();
    			} else {
    				var dc = $("#dealerCodeText").val();
    				$.post("<s:url value='/record/getStroragePaths.action'/>",{dealerCode : dc}, function(data) {
    	         		var datas = data.split(":");
    	         		if(datas[0] == 0) {
    	         			$("#dealerCodeText").attr("disabled", "disabled");
    	 					$("#dealerCodeInput").attr("disabled", "disabled");
    	 					$("#stroragePathBox").show();
    	         			$("#stroragePath").prepend("<option value='0'>请选择...</option>");
    	         			var dirs = datas[1].split(",");
    	         			for(var i = 0; i < dirs.length; i++) {
    	         				var dir = dirs[i].replace(/\n/g, "").replace(/\r/g, "");
    	         				$("#stroragePath").append("<option value='" + dir + "'>" + dir + "</option>");
    	         			}
    	         		} else {
    	         			$.ligerDialog.alert('该经销商尚未上传数据!', '提示', 'none'); 
    	         		}});
    			}
    		});
        }
        
        function handleChange() {
        	var val = $("#stroragePath").val();
        	if(val != 0) {
        		$("#ts").val(val);
        		$("#delBox").show();
        	} else {
        		$("#delBox").hide();
        	}
        }
</script>
<style type="text/css">
  .btn {background-color:#FFF; border:1px solid #CDCDCD; height:22px; width:120px;}
</style>
</head>
<body style="padding:10px">
	<input type="hidden" id="ts"/>
	<h3>删除统计数据</h3>
	<div id="paramBox" style="margin: 5px;">
		<div id="dealerCodeBox" style="padding:2px;">
			<label style="width: 158px; height: 20px;">请先输入经销商网络代码:</label>
			<input type="text" id="dealerCodeText" name="dealerCodeText" class="l-text" style="width: 120px;  height: 20px;"/>
			<input type="button" id="dealerCodeInput" onclick="inputDealerCode()" value="输入" class="btn"/>
		</div>
		<div id="stroragePathBox" style="padding:2px;">
			<label id="stroragePathLabel" style="width: 158px; height: 20px;">请选择原始数据上传日期:</label>
			<select id="stroragePath" style="width: 120px; height: 20px;" onchange="handleChange()"></select>
		</div>
		<div id="delBox">
			<input type="button" id="delBtn" onclick="deleteData()" value="删除" class="btn"/>
		</div>
		<div id="infoBox">
			<span>正在删除... ...</span>
		</div>
	</div>
</body>
</html>